package com.mo.star.once;

import com.mo.star.mapper.UsertableMapper;
import com.mo.star.pojo.User;
import com.mo.star.service.impl.UsertableServiceImpl;
import com.mo.star.util.UUIDUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

@Component
public class InsertUsers {
    @Resource
    private UsertableMapper userMapper;
    @Resource
    private UsertableServiceImpl userService;

    /**
     * 批量导入数据
     */
 //   @Scheduled(fixedDelay = 5000)
    public void doInsertUser(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final  int INSERT_NUM= 100;
        List<User> userList = new ArrayList<>();
        Date d = new Date(2024,8,9);
        for (int i = 0; i < INSERT_NUM; i++) {
            User user = new User();
            user.setId(UUIDUtil.getUUID());
            user.setUsername("云合");
            user.setTags("[]");
            user.setGender("男");
            user.setPwd("123456");
            user.setPhone("18269257328");
            user.setEmail("heyun_li@foxmail.com");
            user.setIsValue("0");
            user.setCreateDate(d);
            user.setIsDelete("0");
            user.setYhsf(0);
            userList.add(user);
        }

        userService.saveBatch(userList,10);
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());
    }
}
